import request from '@/config/axios'

// 案件-人员关系 API
export const CasePersonRelationApi = {
  // 新增案件-人员关系
  batchCreateCasePersonRelation: async (data: { personIdList: any; caseId: String | undefined }) => {
    return await request.post({
      url: `/member/case-person-relation/create`,
      data
    });
  },

  // 删除案件-人员关系
  deleteCasePersonRelation: async (warnConfigId: String, personId: number) => {
    // 使用模板字符串使URL拼接更清晰
    return await request.delete({
      url: `/member/case-person-relation/delete`,
      params: { warnConfigId, personId }
    })
  },
}

// 案件管理 VO
export interface CasesVO {
  id: string // 案件ID
  caseName: string // 案件名称
  description: string // 描述
  delFlag: number // 删除状态
  createBy: string // 创建人
  updateBy: string // 更新人
}

// 统一预警DTO接口定义
export interface UnifiedWarningDTO {
  id: number;
  personId: number;
  warningConditionId: number;
  warningTime: Date;  // 替换为Date类型
  warningContent: string;
  createTime: Date;   // 替换为Date类型
  warnType: number;
  warnTypeText: string;
  fenceType: number;
  lng: number;
  lat: number;
  isRead: boolean;
  gatherId: number;
  configId: string;
  address: string;
  locationTime: Date; // 替换为Date类型
  sourceTable: string;
  idNumber: string;
  personName: string;
  avatar: string;
  warnPersonCount: number;
  gatherName: string // 聚集条件名称
  startTime: Date // 聚集开始时间
  endTime: Date // 聚集结束时间
  gatherAddress: string // 聚集地址
}

// 案件管理 VO
export interface CasesVO {
  id: string // 案件ID
  caseName: string // 案件名称
  description: string // 描述
  delFlag: number // 删除状态
  createBy: string // 创建人
  updateBy: string // 更新人
}

// 预警统计DTO接口定义
export interface WarningTypeCountDTO {
  warnType: number;
  count: number;
  warnTypeName: string;
}

// 案件管理 API
export const CasesApi = {
  // 查询案件管理分页
  getCasesPage: async (params: any) => {
    return await request.get({ url: `/member/cases/page`, params })
  },

  // 查询案件管理详情
  getCases: async (id: string) => {
    return await request.get({ url: `/member/cases/get?id=` + id })
  },

  // 新增案件管理
  createCases: async (data: CasesVO) => {
    return await request.post({ url: `/member/cases/create`, data })
  },

  // 修改案件管理
  updateCases: async (data: CasesVO) => {
    return await request.put({ url: `/member/cases/update`, data })
  },

  // 删除案件管理
  deleteCases: async (id: number) => {
    return await request.delete({ url: `/member/cases/delete?id=` + id })
  },

  // 导出案件管理 Excel
  exportCases: async (params) => {
    return await request.download({ url: `/member/cases/export-excel`, params })
  },

  // 新增：获取案件最新预警列表
  getCaseLatestWarnPage: async (params: any) => {
    return await request.get({
      url: `/member/warning-individual/caseLatestWarnPage`,
      params
    })
  },

  getCaseHomeLatestWarnPage: async (params: any) => {
    return await request.get({
      url: `/member/warning-individual/caseHomeLatestWarnPage`,
      params
    })
  },

  getPersonLatestWarnPage: async (params: any) => {
    return await request.get({
      url: `/member/warning-individual/personLatestWarnPage`,
      params
    })
  },

  // 新增：获取今日预警类型统计（用于饼图）
  countTodayWarningsByType: async (caseId: string | string[]) => {
    return await request.get({
      url: `/member/warning-individual/count-today-by-type`,
      params: { caseId: caseId }
    })
  },

  countHomeTodayWarningsByType: async () => {
    return await request.get({
      url: `/member/warning-individual/count-home-today-by-type`
    })
  }
}
